package leetcode_500;

/**
 *@author 周杨
 *TotalHammingDistance_477 判断一个int数组里的ham距离
 *describe:用位运算符 AC 18%
 *2018年8月30日 下午4:20:10
 */
public class TotalHammingDistance_477 {
	
	public static void main(String[] args) {
		TotalHammingDistance_477 test=new TotalHammingDistance_477();
		System.out.println(test.totalHammingDistance(new int[] {5,2,6}));
	}
	
	public int totalHammingDistance(int[] nums) {
		int res=0;
        int i=0;
        while(i<32) {
        	int count=0;
        	for(int j=0;j<nums.length;++j) {
        		if((nums[j]&1)==0)//二进制位的为0个数
        			++count;
        		nums[j]>>=1;
        	}
        	res+=(count*(nums.length-count));
        	++i;
        }
        return res;
    }
}
